// See LICENSE for license details.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "hbird_sdk_soc.h"
#include "insn.h"

void testlwsw();
void testlbsb();

int main(void)
{
	testlwsw();
//	testlbsb();
	return 0;
}

void testlbsb()
{
	volatile int i = 0;
	unsigned int array[LEN]= {10,20,30,40,50,60, 70, 80};
	volatile unsigned int init_buf[LEN] = {0};
	printf("lbuf start! \r\n");
	custom_lbuf((int)array);
	printf("lbuf completed! \r\n");
	custom_sbuf((int)init_buf);
	for(;i<LEN; i++){
		printf("init_buf[%d]=%d \n",i,init_buf[i]);
	}
	printf("sbuf completed! \r\n");
}

void testlwsw()
{
	unsigned int a1, a2;
	unsigned int addr;
	asm volatile(
			"li t1, 0xf\n\t"
			"mv %0,	t1\n\t"
			:"=r"(a1)
	);
	asm volatile (
			"li t2, 0x5\n\t"
			"mv %0,	t2\n\t"
			:"=r"(a2)
	);
	asm volatile(
			"li t3, 0xc\n\t"
			"mv %0,	t3\n\t"
			:"=r"(addr)
	);
	printf("initial: a1=0x%x, a2=0x%x \r\n", a1, a2);
    // lw.nj rs2, (rs1)

	custom_lwnj(addr,a1);
//    asm volatile (
//       ".insn r 0x0b, 3, 0, x0, %1, %0"
//    	:
//    	:"r"(a1),"r"(addr)
//     );
    printf("Hello World\r\n");
    a2 = custom_swnj(addr);
//    asm volatile (
//       ".insn r 0x0b, 6, 1, %0, %1, x0"
//    	:"=r"(a2)
//    	:"r"(addr)
//     );
    printf("ld_sd: a1=0x%x, a2=0x%x \r\n", a1, a2);
}
